package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.WhPrinterConfig;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.IWhPrinterConfigService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/system/common")
public class SysCommonController {

    @Resource
    private ISysDictDataService dictDataService;
    @Resource
    private IWhPrinterConfigService whPrinterConfigService;

    /**
     * 获取国家列表
     * @return
     */
    @RequestMapping("/country_options")
    public AjaxResult countryOptions() {
        return AjaxResult.success(dictDataService.countryDic());
    }

    /**
     * 获取国家列表
     * @return
     */
    @RequestMapping("/printer_options")
    public AjaxResult printerOptions() {
        WhPrinterConfig whPrinterConfig = new WhPrinterConfig();
        whPrinterConfig.setStatus(2);
        List<WhPrinterConfig> list = whPrinterConfigService.selectWhPrinterConfigList(whPrinterConfig);
        List<Map<String, Object> > mapList = new ArrayList<>();
        for (WhPrinterConfig printerConfig : list) {
            Map<String, Object> map = new HashMap<>();
            map.put("value", printerConfig.getId());
            map.put("label", printerConfig.getCname());
            mapList.add(map);
        }
        return AjaxResult.success(mapList);
    }
}
